class StateSweeper < ActionController::Caching::Sweeper
  observe Deposito, Destino, Transportadora, Tipo, Armazenamento, Setting, Transporte, Status

  def after_save(model)
    expire_cache(model)
  end

  def after_destroy(model)
    expire_cache(model)
  end
  
  def after_update(model)
    expire_cache(model)
  end  
  
  private

  def expire_cache(model)
    
    puts "---------APAGANDO O CACHE COM SWEEPERS--------------" 
  
    expire_page :controller => 'transportes', :action => 'new'

    if File.exist? $RAILS_CACHE_ROOT
      FileUtils.rm_rf(Dir[File.join($RAILS_CACHE_ROOT, "*")])
    end   

  end

end